﻿Imports System.IO

Public Class FrmCall
    Dim x As Integer = 1
    Dim Folder As String
    Dim Loads As Boolean = True
    Dim Begin As Boolean = False
    Dim Finish As Boolean = False
    Dim Fajr As Boolean
    Private Sub TmrCallAnimate_Tick(sender As Object, e As EventArgs) Handles TmrSetInterval.Tick

        If Bangbej.playState = 3 Then
            TmrBangbezh.Interval = Bangbej.currentMedia.duration * 1000
        End If

    End Sub

    Private Sub FrmCall_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim BangbezhINI As New Ini
        Dim OptionsBBJ As New Ini
        PicTitle.Size = LblPrrNm.Size
        PicTitle.Location = LblPrrNm.Location

        PicBody.Size = LabelCall.Size
        PicBody.Location = LabelCall.Location

        PicForm.Size = Me.Size
        PicForm.Left = 0
        PicForm.Top = 0
        PicLine.Height = PicForm.Height
        PicLine.Width = 1

        LabelCall.ForeColor = MyColor
        BtnClose.FlatAppearance.MouseOverBackColor = MyColor
        OptionsBBJ.Load(Application.StartupPath & "\Data\Options.Bbj")
        BangbezhFile = OptionsBBJ.GetStringField("Options", "Bangbezh")
        BangbezhINI.Load(Application.StartupPath & "\Data\Dangakan\" & BangbezhFile) 'Load Data into it
        Folder = BangbezhINI.GetStringField("Bangbezh", "Folder")

        'Sets the position of FrmCall
        Me.Left = (My.Computer.Screen.WorkingArea.Width - Me.Width)
        Me.Top = 90

        FrameBottom.BackColor = MyColor
        FrameTop.BackColor = MyColor
        FrameLeft.BackColor = MyColor
        FrameRight.BackColor = MyColor
        PicLine.BackColor = MyColor
        Bangbej.settings.volume = Volume

        Fajr = False
        'Set the text of LblPrrNm to current prayer's name
        If FixMins.TotalMinutes > 0 Then
            Dim x As Short
            Select Case NxtPrayer
                Case 0 'Case Fajr
                    x = 0
                    Fajr = True
                Case 2 'Case Dhuhr
                    x = 2
                Case 5 'Case Isha
                    x = 5
                Case 4 'Case Maghrib
                    x = 4
                Case 3 'Case Asr
                    x = 3
            End Select
            Select Case FixMins.TotalMinutes
                Case 5
                    LblPrrNm.Text = "٥ خولەك ماوە بۆ بانگی " & Prayers(x)
                Case 10
                    LblPrrNm.Text = "١٠ خولەك ماوە بۆ بانگی " & Prayers(x)
                Case 15
                    LblPrrNm.Text = "١٥ خولەك ماوە بۆ بانگی " & Prayers(x)
            End Select
        Else
            If Now.Hour = FajrD.Hour Or Now.Hour = (FajrD.Hour - 1) Then 'Case Fajr
                LblPrrNm.Text = My.Resources.TimeForFajr
                Fajr = True
            ElseIf Now.Hour = DhuhrD.Hour Or Now.Hour = (DhuhrD.Hour - 1) Then 'Case Dhuhr
                LblPrrNm.Text = My.Resources.TimeForDhuhr
            ElseIf Now.Hour = AsrD.Hour Or Now.Hour = (AsrD.Hour - 1) Then  'Case Asr
                LblPrrNm.Text = My.Resources.TimeForAsr
            ElseIf Math.Abs(DateDiff(DateInterval.Second, IshaD, Now)) < Math.Abs(DateDiff(DateInterval.Second, MaghribD, Now)) Then 'Case Isha
                LblPrrNm.Text = My.Resources.TimeForIsha
            ElseIf Math.Abs(DateDiff(DateInterval.Second, MaghribD, Now)) < Math.Abs(DateDiff(DateInterval.Second, IshaD, Now)) Then  'Case Maghrib
                LblPrrNm.Text = My.Resources.TimeForMaghrib
            Else
                MsgBox("hullo")

            End If
        End If

    End Sub

    Sub PlayAudio(ByVal FileName As String)
        Bangbej.URL = FileName
    End Sub

    Private Sub TmrBangbezh_Tick(sender As Object, e As EventArgs) Handles TmrBangbezh.Tick

        Select Case x
            Case 1
                LabelCall.Text = My.Resources.AllahuAkbar
            Case 3
                LabelCall.Text = My.Resources.AshAll
            Case 5
                LabelCall.Text = My.Resources.AshMu
            Case 7
                LabelCall.Text = My.Resources.HaiSal
            Case 9
                LabelCall.Text = My.Resources.HaiFal
            Case 11
                If Fajr = True Then
                    LabelCall.Text = My.Resources.AsaltuXayr
                Else
                    x += 2
                    LabelCall.Text = My.Resources.AllahuAkbar
                End If
            Case 13
                LabelCall.Text = My.Resources.AllahuAkbar
            Case 14
                LabelCall.Text = My.Resources.La
        End Select
        If TmrBangbezh.Interval > 200 Then
            PlayAudio(Application.StartupPath & "\Data\Dangakan\" & Folder & "\" & x & ".mp3")

            If x < 15 Then
                x = x + 1
                PicBody.Left = 0
                TmrAnimate.Enabled = True
            Else
                Over()
            End If

        End If

    End Sub

    Private Sub BtnClose_Click(sender As Object, e As EventArgs) Handles LblPrrNm.Click, LabelCall.Click, BtnClose.Click, PicBody.Click, PicTitle.Click
        Over()
    End Sub

    Private Sub Bangbezh_CurrentMediaItemAvailable(sender As Object, e As AxWMPLib._WMPOCXEvents_CurrentMediaItemAvailableEvent) Handles Bangbej.CurrentMediaItemAvailable
        TmrBangbezh.Enabled = True
    End Sub

    Private Sub TmrAnimate_Tick(sender As Object, e As EventArgs) Handles TmrAnimate.Tick
        'If frmload has not been prepared yet
        If Loads Then

            If Begin = False Then 'If it was time to show form transition

                If PicForm.Right > 0 Then
                    PicForm.Left -= 10
                    PicLine.Left = PicForm.Right + 1
                    PicLine.Top = PicForm.Top
                Else
                    PicForm.Left = -Me.Width * 2
                    Begin = True
                    LblPrrNm.Visible = True
                    LabelCall.Visible = True
                    BtnClose.Visible = True
                    TmrBangbezh.Enabled = True
                    TmrSetInterval.Enabled = True

                    PlayAudio(Application.StartupPath & "\Data\Dangakan\" & Folder & "\1.mp3")
                    x += 1

                End If

            End If

            'If LblPrrNm's Transition has not been played yet and it was not the time for form's transition
            If Begin Then
                If PicTitle.Right > LblPrrNm.Left Then
                    PicTitle.Left -= 5
                Else
                    PicTitle.Left = -Me.Width - Me.PicTitle.Width
                    Loads = False
                End If
            End If
        End If

        'Do LblCall's Transitions.
        If Begin Then
            If PicBody.Right > 0 Then
                PicBody.Left -= 1
            Else : TmrAnimate.Enabled = False
            End If
        End If

    End Sub
    Sub Over()
        TmrEnd.Enabled = True
    End Sub

    Private Sub TmrEnd_Tick(sender As Object, e As EventArgs) Handles TmrEnd.Tick
        Bangbej.URL = Nothing
        TmrAnimate.Enabled = False
        PicForm.Width = Me.Width * 2
        PicForm.Left += 10
        PicLine.Left = PicForm.Right
        If PicForm.Left > -10 Then
            Me.Close()
        End If
    End Sub

    Private Sub LblPrrNm_TextChanged(sender As Object, e As EventArgs) Handles LblPrrNm.TextChanged
        LblPrrNm.Text.Replace("1", "١")
        LblPrrNm.Text.Replace("5", "٥")
        LblPrrNm.Text.Replace("0", "٠")
    End Sub

End Class